import React, { useRef } from 'react'
import { Animated, Button, SafeAreaView, StyleSheet, Text, View } from 'react-native'

export default function Animated_01() {
  // 初始化动画
  const fadeAnim = useRef(new Animated.Value(0)).current;

  const change = () => {
    Animated.spring(fadeAnim, {
      toValue: 100,
      useNativeDriver: false,
      /* 
      speed: 控制动画速度。默认值 12.
      bounciness: 控制弹性。默认值 8.
      */
      bounciness: 25,
      speed: 15
    }).start()
  }

  return (
    <SafeAreaView style={styles.container}>
      <Animated.View
        style={
          {
            opacity: fadeAnim,
          }
        }>

      </Animated.View>

      <Animated.View
        style={
          [
            styles.fadingContainer,
            {
              marginLeft: fadeAnim
            }
          ]
        }
      >
        <Text style={styles.fadingText}>use spring</Text>
      </Animated.View>
      <View style={styles.buttonRow}>
        <Button title='平移' onPress={change}  ></Button>
      </View>
    </SafeAreaView>
  )
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  fadingContainer: {
    padding: 20,
    backgroundColor: 'powderblue',
  },
  fadingText: {
    fontSize: 28,
  },
  buttonRow: {
    flexBasis: 100,
    justifyContent: 'space-evenly',
    marginVertical: 16,
  },
});